import { defineConfig } from '@rsbuild/core'
import { pluginVue } from '@rsbuild/plugin-vue'
import { pluginSass } from '@rsbuild/plugin-sass'
import AutoImport from 'unplugin-auto-import/rspack'
import Components from 'unplugin-vue-components/rspack'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'

export default defineConfig({
  plugins: [pluginVue(), pluginSass()],
  source: {
    alias: {
      '@': resolve('./src')
    },
    entry: {
      index: './src/main.ts'
    }
  },
  tools: {
    rspack: {
      plugins: [
        AutoImport({
          dts: true,
          eslintrc: { enabled: true },
          resolvers: [ElementPlusResolver()],
          include: [
            /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
            /\.vue$/,
            /\.vue\?vue/, // .vue
            /\.md$/ // .md
          ],
          imports: ['vue', 'vue-router', 'pinia'],
          dirs: ['src/store']
        }),
        Components({
          dts: true,
          types: [{
            from: 'vue-router',
            names: ['RouterLink', 'RouterView'],
          }],
          extensions: ['vue'], //指定文件的后缀名
          resolvers: [ElementPlusResolver()],
          dirs: ['src/components/'] //指定路径，自动导入自定义组件
        })
      ]
    }
  },
  html: {
    title: 'Hello World'
  },
  server: {
    compress: false,
    host: '0.0.0.0',
    port: 5000,
    proxy: {}
  }
})
